﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.effects {
    import Classes.*;

    public class ShakeEffect extends MapResourceEffect {

        private static const SOURCE_SPEED:Number = 20;

        private var m_strength:Number;
        private var m_speed:Number;
        private var m_numFrames:Number;
        private var m_isActive:Boolean;
        private var m_frameCount:Number;
        private var m_directionX:Number;
        private var m_originalX:Number;
        private var m_offsetX:Number;
        private var m_minOffsetX:Number;
        private var m_maxOffsetX:Number;
        private var m_isInitialized:Boolean;

        public function ShakeEffect(_arg1:MapResource, _arg2:Number=0.05, _arg3:Number=1, _arg4:Number=-1){
            m_mapResource = _arg1;
            this.m_strength = _arg2;
            this.m_speed = (SOURCE_SPEED * _arg3);
            this.m_numFrames = _arg4;
            this.m_isActive = true;
            this.m_isInitialized = false;
            if (m_mapResource.content){
                this.init();
            };
            super(_arg1);
        }
        override public function animate(_arg1:uint):Boolean{
            if (!this.m_isActive){
                return (this.m_isActive);
            };
            if (m_mapResource.content){
                if (!this.m_isInitialized){
                    this.init();
                    return (this.m_isActive);
                };
                if (this.m_numFrames >= 0){
                    this.m_frameCount = (this.m_frameCount + 1);
                    if (this.m_frameCount > this.m_numFrames){
                        this.cleanUp();
                        return (this.m_isActive);
                    };
                };
                this.m_offsetX = (this.m_offsetX + (this.m_speed * this.m_directionX));
                if (this.m_offsetX > this.m_maxOffsetX){
                    this.m_offsetX = this.m_maxOffsetX;
                    this.m_directionX = -1;
                } else {
                    if (this.m_offsetX < this.m_minOffsetX){
                        this.m_offsetX = this.m_minOffsetX;
                        this.m_directionX = 1;
                    };
                };
                m_mapResource.content.x = (this.m_originalX + this.m_offsetX);
            };
            return (this.m_isActive);
        }
        override public function cleanUp():void{
            m_mapResource.content.x = this.m_originalX;
            this.m_isActive = false;
        }
        private function init():void{
            this.m_isInitialized = true;
            this.m_frameCount = 0;
            this.m_directionX = 1;
            this.m_originalX = m_mapResource.content.x;
            this.m_maxOffsetX = ((m_mapResource.content.width >> 1) * this.m_strength);
            this.m_minOffsetX = -(this.m_maxOffsetX);
            this.m_offsetX = 0;
            m_mapResource.content.x = (this.m_originalX + this.m_minOffsetX);
        }

    }
}//package Classes.effects 
